package com.aliyun.messagemgt.sendplugin;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName: SendStrategyFactory
 * @Description: 策略工厂类
 * @Author: wugongzi
 * @Date: 2021/8/30 10:40
 * @Version: 1.0
 */
@Component
public class SendStrategyFactory implements ApplicationRunner {
    private static Map<Integer, SendStrategy> sendStrategyMap = new ConcurrentHashMap<>();

    public static SendStrategy getByType(Integer type) {
        return sendStrategyMap.get(type);
    }

    @Override
    public void run(ApplicationArguments args) {
        // TODO 从数据库查询出所有的策略放入map中
        // sendStrategyMap.put();
    }

    public static void register(Integer type, SendStrategy sendStrategy) {
        sendStrategyMap.put(type, sendStrategy);
    }
}
